import { Controller, Get, Post, UseGuards } from '@nestjs/common';
import { Req } from '@nestjs/common/decorators';
import { AppService } from './app.service';
import { AllowNoToken } from './decorators/token.decorator';
import { LocalAuthGuard } from './auth/local-auth.guard';
import { AuthService } from './auth/auth.service';
import { responseMessage } from '@/utils';
import { AllowNoPermission } from '@/decorators/permission.decorator';

@Controller()
export class AppController {
  constructor(
    private readonly appService: AppService,
    private readonly authService: AuthService,
  ) {}

  @Get()
  @AllowNoToken()
  getHello(): string {
    return this.appService.getHello();
  }

  @Post('auth/login')
  @AllowNoToken()
  @UseGuards(LocalAuthGuard)
  async login(@Req() req) {
    const data = await this.authService.login(req.user);
    return responseMessage(data);
  }

  @Get('user/info')
  @AllowNoPermission()
  async getInfo(@Req() req) {
    return responseMessage(req.user);
  }
}
